import { onCheckCode } from "@/api/baseData/testStandard";
import { getOffice } from "@/api/common";

/**
 * @description 表格列对象
 */

export default function getColumns(id?: any) {
  return [
    {
      title: "标准编码",
      key: "standardCode",
      width: 100,
      align: "center",
      ellipsis: true,
      tooltip: true,
      formatData: false,
      search: {
        show: true,
      },
      form: {
        order: 1,
        formItem: {
          rules: [
            {
              required: true,
              trigger: "change",
              message: "标准编码为必填项",
            },
            {
              trigger: "blur",
              asyncValidator: (rule, value) => {
                return new Promise((resolve, reject) => {
                  if (value) {
                    let parmas: any = { standardCode: value };
                    if (id) {
                      parmas.id = id;
                    }
                    onCheckCode(parmas)
                      .then(() => {
                        resolve(true);
                      })
                      .catch(() => {
                        reject("标准编码已经存在");
                      });
                  } else {
                    reject("标准编码为必填项");
                  }
                });
              },
            },
          ],
        },
      },
      addForm: {
        show: true,
      },
      editForm: {
        show: true,
      },
      viewForm: {
        show: true,
      },
    },
    {
      title: "标准(方法)名称",
      key: "standardNameZhCn",
      width: 200,
      align: "center",
      ellipsis: true,
      tooltip: true,
      formatData: false,
      search: {
        show: true,
        title: "标准名称",
      },
      form: {
        order: 2,
        name: "Input",
        formItem: {
          rules: [
            {
              required: true,
              trigger: "change",
              message: "标准名称为必填项",
            },
          ],
        },
      },
      addForm: {
        show: true,
      },
      editForm: {
        show: true,
      },
      viewForm: {
        show: true,
      },
    },
    {
      title: "标准英文名称",
      key: "standardNameEn",
      width: 150,
      align: "center",
      form: {
        order: 4,
        component: {
          name: "Input",
        },
      },
      search: {
        show: false,
      },
      addForm: {
        show: true,
      },
      editForm: {
        show: true,
      },
      viewForm: {
        show: true,
      },
    },
    {
      title: "标准(方法)编号",
      key: "methodCode",
      width: 160,
      align: "center",
      form: {
        name: "Input",
        order: 3,
        formItem: {
          rules: [
            {
              required: true,
              trigger: "change",
              message: "标准(方法)编号为必填项",
            },
          ],
        },
      },
      search: {
        show: false,
      },
      addForm: {
        show: true,
      },
      editForm: {
        show: true,
      },
      viewForm: {
        show: true,
      },
    },
    {
      title: "替代标准号",
      key: "replaceMethodCode",
      width: 150,
      align: "center",
      search: {
        show: false,
      },
      form: {
        order: 11,
      },
      addForm: {
        show: true,
      },
      editForm: {
        show: true,
      },
      viewForm: {
        show: true,
      },
    },
    {
      title: "类别",
      key: "standardType",
      width: 100,
      align: "center",
      slot: "standardTypeTpl",
      dict: {
        code: "standard_type",
      },
      search: {
        show: true,
        component: {
          name: "Select",
          filterable: false,
        },
      },
      form: {
        component: {
          name: "Select",
          filterable: false,
        },
        formItem: {
          rules: [
            {
              required: true,
              trigger: "change",
              message: "标准类别为必填项",
            },
          ],
        },
      },
      addForm: {
        show: true,
        title: "标准类别",
        order: 5,
      },
      editForm: {
        show: true,
        title: "标准类别",
        order: 5,
      },
      viewForm: {
        show: true,
        title: "标准类别",
        order: 5,
      },
    },
    {
      title: "标准来源",
      key: "standardSource",
      width: 100,
      align: "center",
      type: "Input",
      addForm: {
        order: 6,
      },
      editForm: {
        order: 6,
      },
      viewForm: {
        order: 6,
      },
    },
    {
      title: "标准状态",
      key: "standardStatus",
      width: 100,
      align: "center",
      slot: "standardStatusTpl",
      dict: {
        code: "standard_status",
      },
      search: {
        show: true,
        component: {
          name: "Select",
          filterable: false,
        },
      },
      form: {
        component: {
          name: "Select",
          filterable: false,
        },
        formItem: {
          rules: [
            {
              required: true,
              trigger: "change",
              message: "标准状态为必填项",
            },
          ],
        },
      },
      addForm: {
        show: true,
        order: 8,
      },
      editForm: {
        show: true,
        order: 8,
      },
      viewForm: {
        show: true,
        order: 8,
      },
    },
    {
      title: "语种",
      key: "languageType",
      width: 100,
      align: "center",
      slot: "languageTypeTpl",
      dict: {
        code: "language_type",
      },
      search: {
        show: true,
        component: {
          name: "Select",
          filterable: false,
        },
      },
      form: {
        component: {
          name: "Select",
          filterable: false,
        },
      },
      addForm: {
        show: true,
        order: 7,
      },
      editForm: {
        show: true,
        order: 7,
      },
      viewForm: {
        show: true,
        order: 7,
      },
    },
    {
      title: "档案号",
      key: "fileNo",
      width: 100,
      show: false,
      addForm: {
        show: true,
        order: 9,
      },
      editForm: {
        show: true,
        order: 9,
      },
      viewForm: {
        show: true,
        order: 9,
      },
    },
    {
      title: "收文号",
      key: "receiptNo",
      width: 100,
      show: false,
      addForm: {
        show: true,
        order: 10,
      },
      editForm: {
        show: true,
        order: 10,
      },
      viewForm: {
        show: true,
        order: 10,
      },
    },
    {
      title: "说明",
      key: "remarks",
      width: 100,
      align: "center",
      ellipsis: true,
      tooltip: true,
      formatData: false,
      search: {
        show: false,
      },
      form: {
        show: true,
        order: 14,
        component: { type: "textarea", rows: "2" },
        grid: { span: "24" },
      },
    },
    {
      title: "适用范围",
      key: "scopeOfApplication",
      width: 100,
      align: "center",
      search: {
        show: false,
      },
      form: {
        show: true,
        order: 11,
      },
    },
    {
      title: "责任部门",
      key: "officeCode",
      width: 100,
      show: false,
      dict: {
        fetchDictFunc: () => {
          return getOffice({ parentCode: "001" }).then((res: any) => {
            return res.map((item: any) => {
              return {
                label: item.officeName,
                value: item.officeCode,
              };
            });
          });
        },
      },
      form: {
        show: true,
        order: 12,
        component: {
          name: "Select",
          filterable: false,
        },
      },
    },
    {
      title: "领域代码",
      key: "domainCode",
      width: 100,
      align: "center",
      show: false,
      form: {
        order: 13,
        show: true,
      },
    },
    {
      title: "添加日期",
      key: "createDate",
      width: 150,
      align: "center",
      viewForm: {
        show: false,
      },
    },
    {
      title: "修改日期",
      key: "updateDate",
      width: 150,
      align: "center",
      viewForm: {
        show: false,
      },
    },
    {
      title: "添加人",
      key: "createByName",
      width: 150,
      align: "center",
      viewForm: {
        show: false,
      },
    },
    {
      title: "操作",
      key: "handle",
      width: 240,
      fixed: "right",
      align: "center",
      slot: "operOptions",
      viewForm: {
        show: false,
      },
    },
  ];
}
